﻿@using Seal.Model;
@using System.Drawing;
@{
    ReportViewTemplate Template = Model;

    //Template Name
    Template.Name = ReportViewTemplate.ModelHTMLName;

    //If for model, the Model parameter object used for the parsing is the Model instead of the Report
    Template.ForModel = true;

    //Default chart configuration
    Template.ChartConfigurationXML = "<?xml version=\"1.0\" encoding=\"utf-16\"?><Chart Size=\"600, 400\"><Legends><Legend Name=\"Legend1\"></Legend></Legends><Titles><Title Name=\"Title1\" Visible=\"False\"></Title></Titles><ChartAreas><ChartArea Name=\"ChartArea1\"></ChartArea></ChartAreas></Chart>";
    
    //Parameters for this template
    Template.Parameters.Add(new Parameter() { Name = "invert_data_tables", DisplayName = "Invert Data Tables", BoolValue = false, Description = "If true, the columns and rows of the data table are swapped from their original presentation" });
    Template.Parameters.Add(new Parameter() { Name = "show_summary_table", DisplayName = "Show Summary table", BoolValue = true, Description = "If true, the summary table is displayed" });
    Template.Parameters.Add(new Parameter() { Name = "show_page_tables", DisplayName = "Show Page tables", BoolValue = true, Description = "If true, the page tables are displayed" });
    Template.Parameters.Add(new Parameter() { Name = "show_data_tables", DisplayName = "Show Data tables", BoolValue = true, Description = "If true, the data tables are displayed" });
    Template.Parameters.Add(new Parameter() { Name = "show_charts", DisplayName = "Show Charts", BoolValue = true, Description = "If true, the charts are displayed" });
    Template.Parameters.Add(new Parameter() { Name = "show_page_separator", DisplayName = "Show Page separator", BoolValue = true, Description = "If true, a separator if displayed between each pages of the model" });
    Template.Parameters.Add(new Parameter() { Name = "data_tables_enabled", Category = ViewParameterCategory.DataTables, DisplayName = "Data Tables feature is enabled", BoolValue = true, Description = "If true, Data Tables feature is enabled to allow pagination, sorting and filtering in tables" });
    Template.Parameters.Add(new Parameter() { Name = "data_tables_sort_enabled", Category = ViewParameterCategory.DataTables, DisplayName = "Data Tables sort is enabled", BoolValue = true, Description = "If true, the sort feature of the Data Tables is enabled" });
    Template.Parameters.Add(new Parameter() { Name = "data_tables_filter_enabled", Category = ViewParameterCategory.DataTables, DisplayName = "Data Tables filter is enabled", BoolValue = true, Description = "If true, the filter feature of the Data Tables is enabled" });
    Template.Parameters.Add(new Parameter() { Name = "data_tables_pagination_enabled", Category = ViewParameterCategory.DataTables, DisplayName = "Data Tables pagination is enabled", BoolValue = true, Description = "If true, the pagination feature of the Data Tables is enabled" });
    Template.Parameters.Add(new Parameter() { Name = "data_tables_pagination_size", Category = ViewParameterCategory.DataTables, DisplayName = "Data Tables pagination size", Value = "50", Enums = new string[] { "10", "25", "50", "100" }, Description = "Number of rows displayed in a page (if pagination is enabled)" });
    Template.Parameters.Add(new Parameter() { Name = "data_tables_show_information", Category = ViewParameterCategory.DataTables, DisplayName = "Data Tables show information", BoolValue = true, Description = "If true, Data Tables display the number of records" });
    Template.Parameters.Add(new Parameter() { Name = "data_tables_show_processing", Category = ViewParameterCategory.DataTables, DisplayName = "Data Tables show processing", BoolValue = true, Description = "If true, Data Tables display a processing message when working" });
    Template.Parameters.Add(new Parameter() { Name = "summary_table_caption", DisplayName = "Summary table caption", Description = "Optional caption or title displayed at the bottom of the summary table" });
    Template.Parameters.Add(new Parameter() { Name = "page_table_caption", DisplayName = "Page table caption", Description = "Optional caption or title displayed at the bottom of the page table" });
    Template.Parameters.Add(new Parameter() { Name = "data_table_caption", DisplayName = "Data table caption", Description = "Optional caption or title displayed at the bottom of the data table" });
    Template.Parameters.Add(new Parameter() { Name = "print_break_after_page", DisplayName = "Print: Force a break after a page", BoolValue = false, Description = "If true, a new page is started after a page is displayed for the print layout" });
    Template.Parameters.Add(new Parameter() { Name = "display_summary_totals", DisplayName = "Totals: Display totals in summary table", BoolValue = true, Description = "If true, the totals are displayed in the summary table" });
    Template.Parameters.Add(new Parameter() { Name = "display_page_totals", DisplayName = "Totals: Display totals in page table", BoolValue = true, Description = "If true, the totals are displayed in the page table" });
    Template.Parameters.Add(new Parameter() { Name = "add_summary_totals_totals", DisplayName = "Totals: Add the total of totals line in summary table", BoolValue = true, Description = "If true, a line containing the totals is added at the end of the summary table" });
    Template.Parameters.Add(new Parameter() { Name = "chart_nvd3_title", DisplayName = "NVD3 Chart Title", Description = "Optional title displayed at the bottom of the NVD3 chart" });
    Template.Parameters.Add(new Parameter() { Name = "chart_show_all_axis_labels", DisplayName = "Chart show all axis labels", BoolValue = false, Description = "If true, force all axis labels to be shown. For NVD3 Chart, the option is only valid for Bar chart." });

    
    
    Template.Parameters.Add(new Parameter() { 
        Name = Parameter.NVD3ConfigurationParameter, Category = ViewParameterCategory.NVD3, EditorLanguage="js", DisplayName = "NVD3 Chart Configuration", Description = "The JavaScript to create and configure the NVD3 chart. The Width and Height are configured in a dedicated CSS parameter.", TextValue = @"chart
.color(d3.scale.category10().range())
//.margin({top: 30, right: 60, bottom: 40, left: 70})
.tooltipContent(function(key, x, y, e, graph) { return '\x3Ch3>'+key+'\x3C/h3>\x3Cp>'+x+'\x3C/p>\x3Cp>\x3Cb>'+y+'\x3C/b>\x3C/p>' ; })
;
//Axis format
if (chart.xAxis != null && chart.xAxis.tickFormat != null) chart.xAxis.tickFormat(XValueFormatter);
if (chart.yAxis != null && chart.yAxis.tickFormat != null) chart.yAxis.tickFormat(YPrimaryValueFormatter);
//For line with focus
if (chart.x2Axis != null && chart.x2Axis.tickFormat != null ) chart.x2Axis.tickFormat(XValueFormatter);                                
if (chart.y2Axis != null && chart.y2Axis.tickFormat != null ) chart.y2Axis.tickFormat(YPrimaryValueFormatter);                                
//For multichart
if (chart.yAxis1 != null && chart.yAxis1.tickFormat != null) chart.yAxis1.tickFormat(YPrimaryValueFormatter);
if (chart.yAxis2 != null && chart.yAxis2.tickFormat != null) chart.yAxis2.tickFormat(YSecondaryValueFormatter);

if (chart.showXAxis != null) chart.showXAxis(true);
if (chart.showYAxis != null) chart.showYAxis(true);

if (chart.showDistX != null) chart.showDistX(true);
if (chart.showDistY != null) chart.showDistY(true);

var hideControls = (chartType == 'scatterChart' || (series.length == 1 && (chartType == 'multiBarChart' || chartType == 'multiBarHorizontalChart')));
if (chart.showControls != null && !hideControls) chart.showControls(true);
if (chart.showControls != null && (printLayout || xLabels.length<=1)) chart.showControls(false);
if (chart.showLegend != null) chart.showLegend(true);
if (chart.useInteractiveGuideline != null) chart.useInteractiveGuideline(true);
//if (chart.rotateLabels != null) chart.rotateLabels(90);  //for Bar
//if (chart.stacked != null) chart.stacked(true); //for Bar
//if (chart.isArea != null) chart.isArea(true); //for Line 
if (chart.interpolate != null) chart.interpolate('cardinal');

//Special for Pie
if (chartType == 'pieChart') {
    chart
    //.margin({top: 10, right: 10, bottom: 10, left: 10})
    .x(function(d) { return xLabels[d.x]})
    .showLabels(true)     
    .labelThreshold(.05)  //Configure the minimum slice size for labels to show up
    .labelType('percent') //Configure what type of data to show in the label. Can be key, value or percent
    .donut(true)          
    .donutRatio(0.35)     //Configure how big you want the donut hole size to be
    .tooltipContent(function(key, y, e, graph) { return '\x3Ch3>'+key+'\x3C/h3>\x3Cp>\x3Cb>'+YPrimaryValueFormatter(y.normalizeNumeric())+'\x3C/b>\x3C/p>' ; })
    ;
}

//Title 
if (chartTitle.length > 0) {
	svg.append('text')
    .attr('x', Math.max(1,svgJQ.width()/2 - 3*chartTitle.length))
    .attr('y', svgJQ.height()-10)
    .style('font-weight', 'bold')
    .style('font-size', '14px')
    .text(chartTitle);
}

//More information at http://nvd3.org/ and http://cmaurer.github.io/angularjs-nvd3-directives/index.html
"
    });
 
    //CSS
    Template.CSS.Add(new Parameter() { Name = "view", DisplayName = "View", Type = ViewParameterType.String, Description = "CSS style for the DIV tag containing the full View", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "page", DisplayName = "Page", Type = ViewParameterType.String, Description = "CSS style for the DIV tag containing the Page of the model", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "summary", DisplayName = "Summary table container", Type = ViewParameterType.String, Description = "CSS style for the DIV tag containing the Summary table of the model", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "summary_table", DisplayName = "Summary table", Type = ViewParameterType.String, Description = "CSS style for the Summary table of the model", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "page_table", DisplayName = "Page table container", Type = ViewParameterType.String, Description = "CSS style for the DIV tag containing the Page table of the model", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "page_table_table", DisplayName = "Page table", Type = ViewParameterType.String, Description = "CSS style for the Page table of the model", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "chart", DisplayName = "Chart container", Value = "page-break-inside:avoid;", Description = "CSS style for the DIV tag containing the Chart of the model", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "chart_chart", DisplayName = "Chart", Value = "", Description = "CSS style for the Chart of the model", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "data_table", DisplayName = "Data table container", Type = ViewParameterType.String, Description = "CSS style for the DIV tag containing the Data table of the model", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "data_table_table", DisplayName = "Data table", Type = ViewParameterType.String, Description = "CSS style for the Data table of the model", Enums = ReportViewTemplate.DefaultCSS, UseOnlyEnumValues = false });
    Template.CSS.Add(new Parameter() { Name = "nvd3_chart", EditorLanguage = "css", DisplayName = "NVD3 Chart", TextValue = "height:400px; width:600px; page-break-inside:avoid;", Description = "CSS style for the SVG tag defining the NVD3 Chart of the model" });
    
    //Allowed template parent names
    Template.ParentNames = new List<string>() { "Report", "Tab Page" };
}
